# -*- coding: ISO-8859-1 -*-
from manager import PROGRAM_VERSION
from distutils.core import setup
import os, sys, py2exe
from glob import glob
import shutil

# removendo todos os scripts compilados
for pycpath in glob(os.path.join(os.getcwd(),"*.pyc")):
    if pycpath.rsplit(".",1)[-1] == "pyc":
        try: os.remove( pycpath )
        except Exception, err:
            print "Err[%s]: %s"%(pycpath, err)
# -----------------------------------------------------

modules = [sys.argv[1]]
sys.argv[1] = "py2exe"

options = {
	'py2exe': {
		'excludes': ["pywin", "pywin.debugger", "pywin.debugger.dbgcon", "pywin.dialogs", "pywin.dialogs.list"],
		'dist_dir': "BaixeAssista_v%s" % PROGRAM_VERSION,
		'packages': ["encodings"]
	}
}
data_files = [
    ("Microsoft.VC90.CRT", glob(os.path.join(os.getcwd(), "DLLS", "*.*"))),
    ("imagens", glob(os.path.join(os.getcwd(), "imagens", "*.*"))),
    ("configs", glob(os.path.join(os.getcwd(), "configs", "*.*"))),
    ("videos", []), ("videos/temp", []), ("update", []), ("logs", []),
    ("configs/database", [])
]
description = "Assista a filmes(streams) enquanto baixa"

setup(
    name = description,
	windows = [{"script": modules[-1], "icon_resources": [(1, "movies.ico")]}],
    zipfile = "lib/shared.zip", 
    description = description, version = PROGRAM_VERSION, 
	options = options, data_files = data_files
)

for dirname in ["jwPlayer", "locale"]:
    src = os.path.join(os.getcwd(), dirname)
    dst = os.path.join(os.getcwd(), options["py2exe"]["dist_dir"], dirname)
    
    if os.path.exists(dst):
        try: shutil.rmtree(dst)
        except Exception, err:
            print "rmdst: %s %s"%(dst, err)
    shutil.copytree(src, dst)